package com.atguigu.jxc.service.impl;

import com.atguigu.jxc.dao.GoodsDao;
import com.atguigu.jxc.domain.ErrorCode;
import com.atguigu.jxc.domain.ServiceVO;
import com.atguigu.jxc.domain.SuccessCode;
import com.atguigu.jxc.entity.Goods;
import com.atguigu.jxc.entity.GoodsType;
import com.atguigu.jxc.entity.Log;
import com.atguigu.jxc.entity.Unit;
import com.atguigu.jxc.service.CustomerReturnListGoodsService;
import com.atguigu.jxc.service.GoodsService;
import com.atguigu.jxc.service.LogService;
import com.atguigu.jxc.service.SaleListGoodsService;
import com.atguigu.jxc.vo.TreeVo;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import java.util.HashMap;
import java.util.List;
import java.util.Map;

/**
 * @description
 */
@Service
public class GoodsServiceImpl implements GoodsService {

    @Autowired
    private GoodsDao goodsDao;

    @Override
    public ServiceVO getCode() {

        // 获取当前商品最大编码
        String code = goodsDao.getMaxCode();

        // 在现有编码上加1
        Integer intCode = Integer.parseInt(code) + 1;

        // 将编码重新格式化为4位数字符串形式
        String unitCode = intCode.toString();

        for(int i = 4;i > intCode.toString().length();i--){

            unitCode = "0"+unitCode;

        }
        return new ServiceVO<>(SuccessCode.SUCCESS_CODE, SuccessCode.SUCCESS_MESS, unitCode);
    }

    /**
     * 获取商品列表
     * @return
     */
    @Override
    public PageInfo<Goods> getGoodsList(int pageNum, int pageSize,String codeOrName, Integer goodsTypeId) {
        PageHelper.startPage(pageNum,pageSize);
        List<Goods> goodsList = goodsDao.getGoodsList(codeOrName,goodsTypeId);
        return new PageInfo<Goods>(goodsList);
    }

    /**
     * 商品树
     * @return
     */
    @Override
    public List<TreeVo> loadTree() {
        int id = 1;
        List<TreeVo> treeVos = goodsDao.loadTree(id);
        return treeVos;
    }

    /**
     * 获取所有的商品单位
     * @return
     */
    @Override
    public List<Unit> getUnit() {
        List<Unit> list = goodsDao.getUnit();
        return list;
    }

    /**
     * 添加商品分类
     * @param goodsTypeName
     * @param pid
     */
    @Override
    public void savaGoodsType(String goodsTypeName, Integer pid) {
//        goodsDao.savaGoodsType(goodsTypeName,pid);
    }

}
